<template>
	<view class="nav">
		<view :style="{height:`${statusHeight}rpx`,background}"></view>
		<view v-if="isHome" class="headNav" :style="{height:`${navHeight}rpx`,lineHeight:`${navHeight}rpx`,background}">
			<text class="city">中部地区</text>
				<navigator 
				    class="search-nav"
					url="/pages/search/index"
					:style="{
						height:`${menu.height*2}rpx`,
						lineHeight:`${menu.height*2}rpx`,
						marginTop:`${menu.top*2-statusHeight}rpx`,
						marginRight:`${menu.width*2 +24}rpx`
					}"
				>
					<text class="search-text">找医院</text>
				</navigator>
			
		</view>
		<view v-else class="navbar" :style="{height:`${navHeight}rpx`,background}">
			<view class="back-icon" @click="backGo">
				<image v-if="pages > 1" src="../../static/resource/navbar/ic_back.png" />
				<image v-else  src="../../static/resource/navbar/ic_home.png" />
			</view>
			<view class="nav-title" v-if="titleText">
				<view :style="{height:`${navHeight}rpx`,lineHeight:`${navHeight}rpx`}">{{titleText}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			background: {
				type:String,
				default: 'rgba(255,255,255,1)'
			},
			color:{
				type:String,
				default:'rgba(0,0,0,1)'
			},
			fontSize:{
				type:Number,
				default:32
			},
			iconWidth:{
				type:Number,
				default:116
			},
			iconHeight:{
				type:Number,
				default:38
			},
			titleText:{
				type:String,
				default:''
			},
			isHome:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				//状态栏高度
				statusHeight:'',
				//内容高度
				navHeight:'',
				//获取页面栈的数量
				pages: getCurrentPages().length,
				//获取胶囊的位置
				menu: uni.getMenuButtonBoundingClientRect()
			}
		},
		beforeMount() {
			this.setNavSize().then(()=>{
				this.$emit('navBarAttached',{
					statusHeight:this.statusHeight,
					navHeight:this.navHeight,
					navBarHeight: this.statusHeight + this.navHeight
				})
			})
		},
		methods: {
			//计算状态栏的高度
			async setNavSize(){
				const {system,statusBarHeight} =await uni.getSystemInfoAsync()
				//console.log('system',statusBarHeight)
				this.statusHeight = statusBarHeight * 2
				if(system.indexOf('iOS') > -1) {
					this.navHeight = 88
				}else{
					this.navHeight = 96
				}
				
			},
			//返回上一级或首页
			backGo(){
				this.pages>1?uni.navigateBack():uni.switchTab({
					url:'/pages/index/index'
				})
			}
			
		}
	}
</script>

<style>
	.nav{
		position: fixed;
		width: 100%;
		top:0;
		left:0;
		z-index: 2;
	}
	.back-icon{
		display: flex;
		align-items: center;
		width: 64rpx;
		height: 100%;
		margin-left:20rpx;
	}
	.back-icon image{
		width: 64rpx;
		height: 64rpx;
	}
	.navbar{
		position: relative;
	}
	.nav-title{
		position:absolute;
		top:0;
		left:50%;
		transform: translate(-50%);
	}
	.headNav{
		padding-left:20rpx;
		display: flex;
	}
	.city {
	    display: inline-block;
	    position: relative;
	    font-size: 30rpx;
	    font-weight: bold;
	    padding-left: 55rpx;
	    background: url()
	        no-repeat left center;
	    background-size: 40rpx;
	}
	
	.city:after {
	    content: ' ';
	    display: inline-block;
	    height: 6px;
	    width: 6px;
	    border-width: 1px 1px 0 0;
	    border-color: #353535;
	    border-style: solid;
	    -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
	    transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
	    position: relative;
	    top: -2px;
	    position: absolute;
	    top: 50%;
	    margin-top: -4px;
	    right: -10px;
	}
	.search-text {
	    display: inline-block;
	    padding-left: 30rpx;
	    color: #bbbbbb;
	    font-size: 26rpx;
	    background: url()
	        no-repeat left center;
	    background-size: 23rpx;
	}

	.nav2-list {
	    margin: 10rpx 20rpx 0 20rpx;
	}
	.nav2-list::after {
	    content: '';
	    display: block;
	    height: 0;
	    line-height: 0;
	    clear: both;
	    visibility: hidden;
	}
	.nav2-item {
	    float: left;
	    margin-top: 20rpx;
	    width: 50%;
	    text-align: center;
	    box-sizing: border-box;
	    padding: 0 5rpx;
	}
	.nav2-pic {
	    width: 100%;
	}
	.nav2-pic image {
	    display: block;
	    width: 100%;
	}
	.nav-list::after {
	    content: '';
	    display: block;
	    height: 0;
	    line-height: 0;
	    clear: both;
	    visibility: hidden;
	}
	.nav-item {
	    float: left;
	    margin-top: 20rpx;
	    width: 20%;
	    text-align: center;
	    padding: 10rpx 0;
	}
	.nav-pic image {
	    display: block;
	    margin: 0 auto;
	    width: 110rpx;
	    height: 110rpx;
	}
	.nav-text {
	    font-size: 24rpx;
	    font-weight: bold;
	    white-space: nowrap;
	    overflow: hidden;
	}
	
	.hosp-list {
	    margin: 10rpx 0 0 0;
	    background: none;
	}
	.hosp-list::before {
	    display: none;
	}
	.hosp-list::after {
	    display: none;
	}
	
	.hosp-item {
	    -webkit-box-align: stretch;
	    -webkit-align-items: stretch;
	    align-items: stretch;
	    padding: 20rpx;
	    margin: 20rpx;
	    border-radius: 10rpx;
	    overflow: hidden;
	    box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
	}
	.hosp-item::before {
	    display: none;
	}
	.hosp-item::after {
	    display: none;
	}
	.hosp-name {
	    font-weight: bold;
	    font-size: 34rpx;
	}
	.hosp-avatar {
	    display: block;
	    width: 200rpx;
	    height: 180rpx;
	    border-radius: 10rpx;
	    overflow: hidden;
	    margin-right: 20rpx;
	}
	.hosp-line {
	    margin-top: 5rpx;
	}
	.hosp-line text {
	    font-size: 26rpx;
	}
	.hosp-rank {
	    font-weight: bold;
	    color: #0bb585;
	    margin-right: 15rpx;
	}
	.hosp-label {
	    font-weight: bold;
	    color: #0ca7ae;
	    margin-right: 15rpx;
	}
	.hosp-intro {
	    color: #999999;
	}
	.search-nav{
		margin-left: 32px;
		flex:1;
		background: #f4f4f4;
		border-radius: 200rpx;
		text-align: center;
	}
</style>
